package com.subdemo.wordmachine.common;

import com.subdemo.wordmachine.common.http.ResultCode;
import lombok.Data;

@Data
public class AjaxResult {
    private Integer code;
    private String msg;
    private Object data;

    // 私有化无参构造
    private AjaxResult(){};


    public static AjaxResult success (Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(ResultCode.SUCCESS.get_code());
        ajaxResult.setMsg(ResultCode.SUCCESS.get_msg());
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult success (String msg,Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(ResultCode.SUCCESS.get_code());
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult success () {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(ResultCode.SUCCESS.get_code());
        ajaxResult.setMsg(ResultCode.FAILED.get_msg());
        ajaxResult.setData(null);
        return ajaxResult;
    }

    public static AjaxResult failed(Integer code,String mag) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(mag);
        return ajaxResult;
    }




}
